pp108 : Writing Scripts for Events

Writing Scripts for Events

This topic describes the procedure to write and edit scripts in the Script Editor.

Use the Script Editor to write or edit scripts for events exposed by the XForms object model.

To write or edit the script for a control:

  1. Open the XForm in the XForms Designer.
  2. Double-click the control, or select Properties.The <control> window for the selected control appears.
  3. Click the Events pane. The Events pane expands to display the events available for the control. The drop-down list of each event displays available functions.
  4. Select a function to attach it with the event, and click .

    Note:
    To create a function, click without selecting any function. The Script tab displays a function name that combines the ID of the control and the name of the event. The Script tab opens to display the Script Editor, using which you can relate the control to the event.

  5. Enter the appropriate script and click to validate it. An alert appears if the script contains any syntax or spelling errors.

    Note:
    The Script Editor does not support the overwrite mode. If you press the Insert key to use this mode, an alert displays and the Script Editor automatically switches to the default Insert mode.

  6. Make the appropriate corrections, and click to save it.

Example

Consider a Button control with 'button1' as ID for which a function needs to be created to display an alert when it is clicked. The Script tab displays a function that combines the control ID with the event name, by default.

function button1_Click(eventObject)
{
alert('Please enter mandatory information to proceed.')
}

After you complete this task:
Click to view the XForm in the Preview window. In case of the above example, clicking the button (with 'button1' ID), displays the alert specified in the Script Editor.


Related tasks

Viewing Scripts
Setting Properties of an XForm